<?php require ('setcookie.html'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html lang="de">
<head>
    <title>Lingomoto - Kontakt - Sprachen lernen</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta name="description" content="Lingomoto - Kontakt - Sprachen lernen" />
    <meta name="language" content="de" />
    <link href="style.css" type="text/css" rel="stylesheet" />
    <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
</head>

<body>

<?php
$_SESSION['logini'] = isset($_SESSION['logini']) ? $_SESSION['logini'] : false;
// read configuration
require ('konfiguration.html');
// read user-data
require ('nutzer.html');
// read header
$link = "kontakt.html";
$langen = 'contact.html';
$langes = 'contacto.html';
$langru = 'contact.html';
require ('kopf.html');
// <!-- horizontal column -->
echo '<div>';
require ('horizontal.html');
echo '</div>';
// <!-- Left Column -->
echo '<div id="left_col">';
require ('vertikal.html');
echo '</div>';

// <!-- Content -->
echo '<div id="content">';
echo '<div id="block5">';

// request for login
if ($_SESSION['logini']== false and $error <> '') {
    require_once ('loginformular.html'); 
}
// if new password, request for change of password
elseif ( $newpass == 1 )
{
    $passwo = isset($_REQUEST['passwo']) ? $_REQUEST['passwo'] : '1';
    $passwo1 = isset($_REQUEST['passwo1']) ? $_REQUEST['passwo1'] : '1';
    $passwo2 = isset($_REQUEST['passwo2']) ? $_REQUEST['passwo2'] : '1';
    $ok='';
    require_once ('neues-passwort.html');
}
else
{
// initialize variables
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : "";
$email = isset($_REQUEST['email']) ? $_REQUEST['email'] : "";
$name  = isset($_REQUEST['name']) ? $_REQUEST['name'] : "";
$message_body  = isset($_REQUEST['message_body']) ? $_REQUEST['message_body'] : "";
$email = trim($email);
$name = trim($name);

if (isset($_REQUEST['submit1_x'])) { $action = 'send_email'; }

if  ( $action <> 'send_email' ) 
{
    // show form
    create_form();
}
else
{
    // Form-Control
if  ( $email == "" OR
      $message_body == "" )
{
    if ( $email == "" )
    { echo "<div class='message'>Bitte E-Mail angeben!</div>"; }
    if ( $message_body == "" )
    { echo "<div class='message'>Bitte Nachricht eingeben!</div>"; }

    create_form();
}
else
{
    // 1. email-check
    $test_mail = filter_var($email, FILTER_VALIDATE_EMAIL);
    if ($test_mail === false)
    {
        echo "<div class='message'>Format der E-Mail-Adresse nicht korrekt. Bitte neu eingeben!</div>"; 

    create_form();
    }
    else
    {
    
    // 2. email-check
    $isValid = true;
    validEmail($email);
    if ( $isValid == false )
    {
        echo "<div class='message'>Format der E-Mail-Adresse nicht korrekt. Bitte neu eingeben!</div>";

    create_form();
    }
    else
    {
    
    // spam-check
    tuersteher_zum_verstehen( $name );
    tuersteher_zum_verstehen( $email );

    // send E-Mail
    send_email();
    echo "<h2>Nachricht versendet</h2>";
    } }
} 
}}

// ----------------------- Functions --------------------------------------------------------------------------------------------

function create_form() {

    global $email,$name,$message_body;

    echo '<form action="'. $_SERVER['PHP_SELF'] . '" method="get" enctype="text/html">';
    echo '<h2>Kontakt</h2>';
    echo '<div id="block4">';
    echo '<br />';
    echo '<label for="name" class="left">Dein Name:</label>';
    echo '<input type="text" class="textfield1" name="name" value="';
    // Content, if form was not completed
    echo $name;
    echo '"><br />';
    echo '<label for="email" class="left">Deine E-Mail-Adresse:</label>';
    echo '<input type="text" class="textfield1" name="email" value="';
    // Content, if form was not completed
    echo $email;
    echo '"><br />';
    echo '<label for="textarea" class="left">Deine Nachricht:</label>';
    echo '<textarea name="message_body" id="message_body" >';
    // Content, if form was not completed
    echo $message_body;
    echo '</textarea><br /><br />';
    echo '<input type="image" src="bilder/buttons/senden.gif" name="submit1" class="right" alt="Senden" title=" Senden " />';
    echo '</div>';
    echo '</form>';
}

function send_email() {

    global $email,$name,$message_body;

    $receiver = "support@lingomoto.com";
    $sender   = $email; 
    $subject    = "Kontaktanfrage";
    $replyto  = $email;
    $mailtext   = $message_body;

    mail( $receiver,
        $subject, 
        $mailtext,
        "From: $name <$sender>\nReply-To: $replyto",
        "-f $receiver");
}

function tuersteher_zum_verstehen( $zum_testen )
{
    $uebeltaeter[] = '%0A';
    $uebeltaeter[] = 'to:';
    $uebeltaeter[] = 'cc:';
    $uebeltaeter[] = 'bcc:';
    $uebeltaeter[] = 'from:';
    $uebeltaeter[] = 'subject:';
    $uebeltaeter[] = 'reply-to:';
    $uebeltaeter[] = 'content-type:';
    $uebeltaeter[] = 'mime-version:';
    $uebeltaeter[] = 'multipart/mixed';
    $uebeltaeter[] = 'content-transfer-encoding:';
    foreach ($uebeltaeter AS $einzeltaeter )
    {
        if (eregi ($einzeltaeter, $zum_testen))
        {
            echo "<p>Bitte keine Sonderzeichen eingeben!</p>";
            // es wird also alles abgebrochen, wenn Gefahr in Verzug ist
            exit;
        }
    }
}

function validEmail($email)
{
   global $isValid;

   $isValid = true;
   $atIndex = strrpos($email, "@");
   if (is_bool($atIndex) && !$atIndex)
   {
      $isValid = false;
   }
   else
   {
      $domain = substr($email, $atIndex+1);
      $local = substr($email, 0, $atIndex);
      $localLen = strlen($local);
      $domainLen = strlen($domain);
      if ($localLen < 1 || $localLen > 64)
      {
         // local part length exceeded
         $isValid = false;
      }
      else if ($domainLen < 1 || $domainLen > 255)
      {
         // domain part length exceeded
         $isValid = false;
      }
      else if ($local[0] == '.' || $local[$localLen-1] == '.')
      {
         // local part starts or ends with '.'
         $isValid = false;
      }
      else if (preg_match('/\\.\\./', $local))
      {
         // local part has two consecutive dots
         $isValid = false;
      }
      else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
      {
         // character not valid in domain part
         $isValid = false;
      }
      else if (preg_match('/\\.\\./', $domain))
      {
         // domain part has two consecutive dots
         $isValid = false;
      }
      else if
      (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',
                 str_replace("\\\\","",$local)))
      {
         // character not valid in local part unless
         // local part is quoted
         if (!preg_match('/^"(\\\\"|[^"])+"$/',
             str_replace("\\\\","",$local)))
         {
            $isValid = false;
         }
      }
      if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A")))

      {
         // domain not found in DNS
         $isValid = false;
      }
   }
   return $isValid;
}

echo '</div>';
echo '</div>';
echo '<div id="adverts">';
echo '<div id="adbox"></div>';
echo '</div>';

require ('fuss.html');
?>

</body>
</html>